package com.zby.filter.util.core.util;

import com.alibaba.fastjson.JSONObject;
import com.zby.filter.vo.enums.TitleEnum;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;

/**
 * Created By zby on 11:16 2019/2/13
 */

public class CommonUtil {

    /**
     * Created By zby on 11:18 2019/2/13
     *
     * @param bigDecimal 参数值
     * @param decimalNum 长度
     */
    public static String toFiexd(BigDecimal bigDecimal, int decimalNum) {
        bigDecimal = null == bigDecimal ? new BigDecimal(BigInteger.ZERO) : bigDecimal;
        StringBuilder decimalStr = new StringBuilder();
        for (int i = 0; i < decimalNum; i++) {
            decimalStr.append("0");
        }
        DecimalFormat decimalFormat = new DecimalFormat("#0." + decimalNum);
        return decimalFormat.format(bigDecimal);
    }

    /**
     * Created By zby on 11:28 2019/2/13
     * 封装枚举
     */
    public static JSONObject builderEnum(TitleEnum titleEnum) {
        JSONObject jsonObject = null;
        if (titleEnum != null) {
            jsonObject = new JSONObject();
            jsonObject.put("key", titleEnum);
            jsonObject.put("value", titleEnum.getTitle());
        }
        return jsonObject;
    }
}
